#include "camera.h"


OrthographicCamera::OrthographicCamera(d_Vec3f c, d_Vec3f d, d_Vec3f u, float tam)
{
	center = c;
	dir = norm(d);
	hor = norm(cross(d, u));
	up = norm(cross(hor,dir));
	size = tam;
	tmin = -1000000;
}
Ray OrthographicCamera::generateRay(d_Vec2f point)
{
	float x = point[0]-.5;
	float y = point[1]-.5;
	return Ray(center+hor*size*x+up*size*y , norm(dir));
}

float OrthographicCamera::getTMin() const
{
	return tmin;
}

////////////Perspective Camera///////////////

PerspectiveCamera::PerspectiveCamera(d_Vec3f c, d_Vec3f d, d_Vec3f u, float tam)
{
	center = c;
	dir = norm(d);
	hor = norm(cross(d, u));
	up = norm(cross(hor,dir));
	angle = tam;
	dist = 1/(2*tan(angle/2));
	tmin = 0;
}
Ray PerspectiveCamera::generateRay(d_Vec2f point)
{
	float x = point[0]-.5;
	float y = point[1]-.5;
	dist = 1/(2*tan(angle/2));
	return Ray(center , norm(dir*dist+hor*x+up*y));
}

float PerspectiveCamera::getTMin() const
{
	return tmin;
}
